﻿using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using MyFramework.Plugins.Core.Configuration.Const;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace MyFramework.Plugins.Core.Configuration
{
    public static class AppSettings
    {
        /// <summary>
        /// 
        /// </summary>
        public static IConfiguration Configuration { get; private set; }
        /// <summary>
        /// 
        /// </summary>
        public static JwtSetting JwtSetting { get; private set; }
        /// <summary>
        /// 
        /// </summary>
        public static Secret Secret { get; private set; }
        /// <summary>
        /// 
        /// </summary>

        public static string TokenHeaderName = "Authorization";
        /// <summary>
        /// 
        /// </summary>
        /// <param name="services"></param>
        /// <param name="configuration"></param>
        public static void Init(IServiceCollection services, IConfiguration configuration)
        {
            Configuration = configuration;
            services.Configure<JwtSetting>(configuration.GetSection("JwtSetting"));
            services.Configure<Secret>(configuration.GetSection("Secret"));

            ////var provider = services.BuildServiceProvider();
            ////IWebHostEnvironment environment = provider.GetRequiredService<IWebHostEnvironment>();
            ////JwtSetting = provider.GetRequiredService<IOptions<JwtSetting>>().Value;

            Configuration.Bind("JwtSetting", JwtSetting);
        }
    }
}
